<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head>
<style>
    body { font-size: 62.5%; }
    label, input { display:block; }
    input.text { margin-bottom:12px; width:95%; padding: .4em; }
    fieldset { padding:0; border:0; margin-top:25px; }
    h1 { font-size: 1.2em; margin: .6em 0; }
    div#users-contain { width: 350px; margin: 20px 0; }
    div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
    div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
    .ui-dialog .ui-state-error { padding: .3em; }
    .validateTips { border: 1px solid transparent; padding: 0.3em; }
  </style>



<link rel="stylesheet" type="text/css" href="/kamaro/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="/kamaro/css/jquery-ui-1.10.4.custom.min.css"/>

<link rel="stylesheet" type="text/css" href="/kamaro/css/bootstrap-theme.min.css"/>
<script type="text/javascript" src="/kamaro/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/kamaro/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/kamaro/js/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="/kamaro/js/jquery-table-sorter.js"></script>

<script>

function saveEmbalagem(action){
    var frm = document.forms[0];
    frm.acao.value = action;
    frm.task.value='save';
    frm.submit();
}

function atualizaObj(i, action){
        var frm = document.forms[0];
         frm.indexList.value = i;
         frm.acao.value = action;
         frm.task.value = 'pegaObj';
         frm.submit();
    }


function excluirEmbalagem(i){
     var frm = document.forms[0];
     frm.indexList.value = i;
     frm.task.value = 'delete';
     frm.submit();
}

function editarEmbalagem(i){
     var frm = document.forms[0];
     frm.task.value = 'alterar';
     frm.submit();
}

$(document).ready(function()
    {
        $("#myTable").tablesorter();
    }
);


/* $(document).ready(function(){
  $("#dialog-form").dialog({
       autoOpen: false,
        height: 350,
        width: 400,
       modal: true
  });
}); */

</script>

</head>
<body>

<html:form action="/cadastrarEmbalagem.do">
    <input type="hidden"  name="indexList"/>


    <input type="hidden" name="task"/>
     <input type="hidden"  name="acao"/>

    <input type="hidden" id="id-embalagem" name="cadastrarEmbalagemForm" property="embalagem.id"/>

<div class="content">
<div class="row">
<div class="col-sm-4">
</br>
  <div id="dialog-form" title="Cadastrar Embalagem">

      <fieldset>

        <table>
        <tr>
            <td><label for="name">Nome</label></td>
            <td><html:text name="cadastrarEmbalagemForm" property="embalagem.descricao" styleClass="text ui-widget-content ui-corner-all"/></td>
         </tr>

       <tr>
            <td>&nbsp;</td>
            <td align="left"><button class="btn btn-primary btn-sm" type="button" onclick="saveEmbalagem('<c:out value = "${cadastrarEmbalagemForm.acao}"/>');"> Salvar </button>
            <button class="btn btn-warning btn-sm" onclick="$('#dialog-form').dialog('close');">Cancelar</button></td>
       </tr>
       </table>
        </fieldset>


     </div>
  </div>

<div class="col-sm-8">

  <h3>Cadastro de Embalagem</h3>
  <c:if test="${not empty cadastrarEmbalagemForm.listarEmbalagem}" >
  <table id="myTable" class="table table-striped table-bordered tablesorter">
    <thead>
      <tr class="ui-widget-header">
        <th>Descricao</th>
        <th colspan="2">&nbsp;</th>
      </tr>
    </thead>
    <tbody>

      <c:forEach var="e" items = "${cadastrarEmbalagemForm.listarEmbalagem}" varStatus = "status" >
      <tr align = "center">
         <td>&nbsp<c:out value= "${e.descricao}" /></td>
         <td>&nbsp<a class="btn btn-primary btn-sm" href="javascript:atualizaObj('<c:out value="${status.count-1}"/>', 'alterar');">Editar</a></td>
         <td>&nbsp <a class="btn btn-danger btn-sm" href="javascript:excluirEmbalagem('<c:out value="${status.count-1}"/>');" >Excluir</a></td>
      </tr>
     </c:forEach>
    </tbody>

  </table>
   </c:if>
</div>
</div>
</html:form>
</body>
</html>